<?php
namespace app\index\controller;

use think\Request;

class Product extends Base
{

    public function index(Request $request)
    {
        $currCategoryId = $this->request->get('category_id',1);

        $product = new \app\common\models\Product();
        $where = ['status'=>1,'category_id'=>1];
        if ($request->get('category_id',0) > 0){
            $where['category_id'] = $request->get('category_id');
        }

        $list = $product->getPageData($where)->toArray();

        //获取分类
        $productCategory = new \app\common\models\ProductCategory();

        $cateList = $productCategory->getMany(['status'=>1,'pid'=>0])->toArray();


        return view('',['list'=>$list,'categoryList'=>$cateList,'currCategoryId'=>$currCategoryId]);
    }

    public function detail($id)
    {
        $product = new \app\common\models\Product();
        $info = $product->getDataById($id)->toArray();

        //上一条
        $prevInfo = $product->getOne(['status'=>1, 'category_id'=>$info['category_id'], 'id'=>['<',$id]], 'id desc');

        //下一条
        $nextInfo = $product->getOne(['status'=>1, 'category_id'=>$info['category_id'], 'id'=>['>',$id]], 'id asc');

        return view('',['info'=>$info,'prevInfo'=>$prevInfo,'nextInfo'=>$nextInfo]);
    }

    public function cases()
    {

        $product = new \app\common\models\Product();
        $where = ['status'=>1,'category_id'=>2];

        $list = $product->getPageData($where)->toArray();

        //获取分类
        $productCategory = new \app\common\models\ProductCategory();

        $cateList = $productCategory->getMany(['status'=>1,'pid'=>0])->toArray();


        return view('',['list'=>$list,'categoryList'=>$cateList]);
    }

    public function case_detail($id)
    {
        $product = new \app\common\models\Product();
        $info = $product->getDataById($id)->toArray();

        //上一条
        $prevInfo = $product->getOne(['status'=>1, 'category_id'=>$info['category_id'], 'id'=>['<',$id]], 'id desc');

        //下一条
        $nextInfo = $product->getOne(['status'=>1, 'category_id'=>$info['category_id'], 'id'=>['>',$id]], 'id asc');

        return view('',['info'=>$info,'prevInfo'=>$prevInfo,'nextInfo'=>$nextInfo]);
    }

}
